﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using QuaManSys.Common;
using QMSDAL;

namespace QuaManSys
{
    public partial class MainPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //CurUser user = (CurUser)Session["CurUser"];
            //if (!IsPostBack)
            //    ShowReminder(user);

            //判断用户是否是非法访问
            if (Session["CurUser"] != null)
            {
                //从session中取出当前用户信息并显示
                CurUser user = (CurUser)Session["CurUser"];
                
                if (!IsPostBack)
                    ShowReminder(user);
            }
            else
            {
                //跳转到登录页面
                Response.Redirect("~/Login.aspx");
            }
        }

        /// <summary>
        /// 根据不同的登录身份显示不同的消息栏
        /// </summary>
        /// <param name="user"></param>
        private void ShowReminder(CurUser user)
        {

            string emId = user.employeeId;
            //根据emID查询雇员角色
            string dept = user.department;  //雇员部门
            //bool proFlag = false;

            #region 内部
            bool inProFlag = false;
            #region 登记
            List<InnerQualityInfo> linRegInfo = Reminder.QueryInReminderList("登记", user);
            if (linRegInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "1A", "A"))
                {
                    inProFlag = true;
                    int inPro = linRegInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlInReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + inPro.ToString() +
                        "条内部质量信息需要登记。";
                    innerHref.NavigateUrl = "InnerInfo/InnerMainPage.aspx";
                    pnlInReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 分发
            List<InnerQualityInfo> linDisInfo = Reminder.QueryInReminderList("分发", user);
            if (linDisInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "1B", "B0"))
                {
                    inProFlag = true;
                    int inPro = linDisInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlInReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + inPro.ToString() +
                        "条内部质量信息需要分发。";
                    innerHref.NavigateUrl = "InnerInfo/InnerMainPage.aspx";
                    pnlInReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 处理
            List<InnerQualityInfo> linProInfo = Reminder.QueryInReminderList("处理", user);
            if (linProInfo.Count != 0)
            {
                int inPro = linProInfo.Count;
                bool needPro = Permission.JudgePermission(user, "1B", "B1");
                
                if (needPro)
                {
                    inProFlag = true;
                    HyperLink innerHref = new HyperLink();
                    pnlInReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + inPro.ToString() +
                        "条内部质量信息需要处理。";
                    innerHref.NavigateUrl = "InnerInfo/InnerMainPage.aspx";
                    pnlInReminder.Controls.Add(new LiteralControl("<br />"));
                }
                
            }
            #endregion

            #region 归档
            List<InnerQualityInfo> linFilInfo = Reminder.QueryInReminderList("归档", user);
            if (linFilInfo.Count != 0)
            {
                int inPro = linFilInfo.Count;
                bool needFile = Permission.JudgePermission(user, "1B", "D1");
                if (needFile)
                {
                    inProFlag = true;
                    HyperLink innerHref = new HyperLink();
                    pnlInReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + inPro.ToString() +
                        "条内部质量信息需要归档。";
                    innerHref.NavigateUrl = "InnerInfo/InnerMainPage.aspx";
                    pnlInReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            if (!inProFlag)
            {
                Label myLabel = new Label();
                myLabel.Text = "当前内部信息已经处理完毕或者您没有处理内部质量信息的权限！";
                pnlInReminder.Controls.Add(myLabel);
                pnlInReminder.Controls.Add(new LiteralControl("<br />"));
            }
            #endregion

            #region 外部
            bool outProFlag = false;
            #region 登记
            List<OuterQualityInfo> loutRegInfo = Reminder.QueryOutReminderList("登记", user);
            if (loutRegInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "2A", "A"))
                {
                    outProFlag = true;
                    int outPro = loutRegInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlOutReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + outPro.ToString() +
                        "条外部质量信息需要登记。";
                    innerHref.NavigateUrl = "OuterInfo/OuterInfoReminderBox.aspx";
                    pnlOutReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 分发
            List<OuterQualityInfo> loutDisInfo = Reminder.QueryOutReminderList("分发", user);
            if (loutDisInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "2B", "B0"))
                {
                    outProFlag = true;
                    int outPro = loutDisInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlOutReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + outPro.ToString() +
                        "条外部质量信息需要分发。";
                    innerHref.NavigateUrl = "OuterInfo/OuterInfoReminderBox.aspx";
                    pnlOutReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 处理
            List<OuterQualityInfo> loutProInfo = Reminder.QueryOutReminderList("处理", user);
            if (loutProInfo.Count != 0)
            {
                int outPro = loutProInfo.Count;
                bool needPro = Permission.JudgePermission(user, "2B", "B1");  
                if (needPro)
                {
                    outProFlag = true;
                    HyperLink innerHref = new HyperLink();
                    pnlOutReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + outPro.ToString() +
                        "条外部质量信息需要处理。";
                    innerHref.NavigateUrl = "OuterInfo/OuterInfoReminderBox.aspx";
                    pnlOutReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 闭环
            List<OuterQualityInfo> loutClsInfo = Reminder.QueryOutReminderList("闭环", user);
            if (loutClsInfo.Count != 0)
            {
                int outPro = loutClsInfo.Count;
                bool needCls = Permission.JudgePermission(user, "2B", "D0");
                if (needCls)
                {
                    outProFlag = true;
                    HyperLink innerHref = new HyperLink();
                    pnlOutReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + outPro.ToString() +
                        "条外部质量信息需要闭环。";
                    innerHref.NavigateUrl = "OuterInfo/OuterInfoReminderBox.aspx";
                    pnlOutReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }

            #endregion

            #region 归档
            List<OuterQualityInfo> loutFileInfo = Reminder.QueryOutReminderList("归档", user);
            if (loutFileInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "2B", "D1"))
                {
                    outProFlag = true;
                    int outPro = loutFileInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlOutReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + outPro.ToString() +
                        "条外部质量信息需要归档。";
                    innerHref.NavigateUrl = "OuterInfo/OuterInfoReminderBox.aspx";
                    pnlOutReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            if (!outProFlag)
            {
                Label myLabel = new Label();
                myLabel.Text = "当前外部信息已经处理完毕或者您没有处理外部质量信息的权限！";
                pnlOutReminder.Controls.Add(myLabel);
                pnlOutReminder.Controls.Add(new LiteralControl("<br />"));
            }

            #endregion

            #region 顾客满意度
            bool cusProFlag = false;

            #region 登记
            List<string> lcusRegInfo = Permission.QueryCusInfoStatus("登记");
            if (lcusRegInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "3A", "A"))
                {
                    cusProFlag = true;
                    int cusPro = lcusRegInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlCusReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + cusPro.ToString() +
                        "条顾客满意度信息需要登记。";
                    innerHref.NavigateUrl = "CusSatiSur/CusSatSurReminderBox.aspx";
                    pnlCusReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 汇总
            List<string> lcusDisInfo = Permission.QueryCusInfoStatus("汇总");
            if (lcusDisInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "3B", "C0"))
                {
                    cusProFlag = true;
                    int cusPro = lcusDisInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlCusReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + cusPro.ToString() +
                        "条顾客满意度信息需要汇总。";
                    innerHref.NavigateUrl = "CusSatiSur/CusSatSurReminderBox.aspx";
                    pnlCusReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 审核
            List<string> lcusFileInfo = Permission.QueryCusInfoStatus("归档");
            if (lcusFileInfo.Count != 0)
            {
                if (Permission.JudgePermission(user, "3B", "C1"))
                {
                    cusProFlag = true;
                    int cusPro = lcusFileInfo.Count;
                    HyperLink innerHref = new HyperLink();
                    pnlCusReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + cusPro.ToString() +
                        "条顾客满意度信息需要审核。";
                    innerHref.NavigateUrl = "CusSatiSur/CusSatSurReminderBox.aspx";
                    pnlCusReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            #region 收集与闭环
            List<string> lcusProInfo = Permission.QueryCusInfoStatus("收集");
            if (lcusProInfo.Count != 0)
            {
                int cusPro = lcusProInfo.Count;
                bool needPro = Permission.JudgePermission(user, "3B", "C2");
                bool needCls = Permission.JudgePermission(user, "3B", "D0");
                if (needCls)
                {
                    cusProFlag = true;
                    HyperLink innerHref = new HyperLink();
                    pnlCusReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + cusPro.ToString() +
                        "条顾客满意度信息需要闭环。";
                    innerHref.NavigateUrl = "CusSatiSur/CusSatSurReminderBox.aspx";
                    pnlCusReminder.Controls.Add(new LiteralControl("<br />"));
                }
                if (needPro)
                {
                    cusProFlag = true;
                    HyperLink innerHref = new HyperLink();
                    pnlCusReminder.Controls.Add(innerHref);
                    innerHref.Text = "您共有" + cusPro.ToString() +
                        "条顾客满意度信息需要收集。";
                    innerHref.NavigateUrl = "CusSatiSur/MainPage.aspx";
                    pnlCusReminder.Controls.Add(new LiteralControl("<br />"));
                }
            }
            #endregion

            if (!cusProFlag)
            {
                Label myLabel = new Label();
                myLabel.Text = "当前顾客满意度信息已经处理完毕或者您没有处理顾客满意度信息的权限！";
                pnlCusReminder.Controls.Add(myLabel);
                pnlCusReminder.Controls.Add(new LiteralControl("<br />"));
            }
            #endregion
        }
    }
}